import router from './index.js'

const whiteList = ['/login', '/register', '/404', '/admin', '/admin/login'];

router.beforeEach((to, from) => {
  const toPath = to.path;
  const isLogin = sessionStorage.getItem('isLogin');
  const isAdminLogin = sessionStorage.getItem('isAdminLogin');
  const fromPath = from.path;
  if (whiteList.includes(toPath)) {
    return true;
  }
  if (isLogin) {
    return true;
  }
  if (isAdminLogin) {
    return true;
  }
  if (fromPath === '/login' || fromPath === '/register') {
    return false;
  }
  return '/login';
});